<?php
class FallasModel extends Zwei_Db_Table
{
	protected $_name = "transacciones";
	protected $_primary = array("id_trans", "fecha_trans");
	protected $_adapter = "an";
	
    public function init(){
    	$form = new Zwei_Utils_Form();
    	if (isset($form->fallas_operacion)) {
		    if ($form->fallas_operacion == "req_comp_promo") {
		        $this->_name = "transacciones_compra";
		    } else if ($form->fallas_operacion == "req_cons_saldo") {
		        $this->_name = "transacciones_csaldo";
	        } else if ($form->fallas_operacion == "req_elim_promo") {
		        $this->_name = "transacciones_elimina";
	        } else if ($form->fallas_operacion == "provisioning") {
		        $this->_name = "transacciones_provisioning";
		    } else {
		        $this->_name = "transacciones";
		    }
    	}        
    }
    
    public function select() 
    {
    	$select = new Zend_Db_Table_Select($this);
    	$select->from($this->_name, 
    	    array(
    	        "modulo",
    	        "estado",
    	        "total" => new Zend_Db_Expr("COUNT(*)")
    	    )
    	);
    	$select->where("estado != ?", "0");
    	$select->group("modulo");
        $select->group("estado");    	

    	return $select;
    }
    
    public function overloadData($data) {
    	$data = $data->toArray();
    	$i = 0; 
        $selectExito = $this->selectExito();    
    }
    
    
    public function selectExito()
    {
    	$select = new Zend_Db_Table_Select($this);
    	$select->from($this->_name, 
            array(
                "modulo",
                "estado",
                "total" => new Zend_Db_Expr("COUNT(*)")
            )
        );
        $select->where("estado = ?", "0");
        $select->group("modulo");
        $select->group("estado");
       
        //Se aplican los mismos parametros de busqueda por $_REQUEST que $this->select()
        $dbObject = new Zwei_Db_Object(new Zwei_Utils_Form());
        
        $select = $dbObject->select();
        return $select;
    }
    
    public function selectPorcentajeErrores()
    {
         $select = new Zend_Db_Table_Select($this);
         return $select;   	
    }
    
    public function selectTotalOperacion()
    {
        $select = new Zend_Db_Table_Select($this);
        $select->from($this->_name, 
            array(
                "modulo",
                "estado",
                "total" => new Zend_Db_Expr("COUNT(*)")
            )
        );
        $select->group("modulo");
        
        //Se aplican los mismos parametros de busqueda por $_REQUEST que $this->select()
        $dbObject = new Zwei_Db_Object(new Zwei_Utils_Form());
        $select = $dbObject->select();

        return $select;
    }
}
